//
//  ViewController.m
//  RAC
//
//  Created by hfzhangzhang on 2018/4/2.
//  Copyright © 2018年 hfzhangzhang. All rights reserved.
//

#import "ViewController.h"
#import "ZZView.h"
#import <ReactiveObjC.h>
#import "NSObject+RACKVOWrapper.h"
#import <RACReturnSignal.h>
#import "LoginViewModel.h"

@interface ViewController ()

@property(nonatomic,strong)id<RACSubscriber> subscriber;

@property (nonatomic, strong) ZZView* zzView;/**< */

@property (nonatomic, strong) UIButton* btn;/**< */

@property (nonatomic, strong) UITextField* tf;/**< */
@property (nonatomic, strong) UILabel* lable;/**< */

@property (weak, nonatomic) IBOutlet UIButton *reSendBtn;
/**  */
@property(assign,nonatomic)int time;
/**   */
@property(nonatomic,strong)RACDisposable  * disposable;
/**   */
@property(nonatomic,strong)RACSignal * signal;


@property (weak, nonatomic) IBOutlet UITextField *accountFiled;
@property (weak, nonatomic) IBOutlet UITextField *pwdFiled;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;

@property(nonatomic,strong) LoginViewModel * loginVM;



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    //监听文本框内容
//        [_textField.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
//            _label.text = x;
//        }];
    //给某个对象的某个属性绑定信号,一旦信号产生数据,就会将内容赋值给属性!
//    RAC(_lable,text) = _tf.rac_textSignal;
//    //只要这个对象的属性发生变化..哥么信号就发送数据!!
//    [RACObserve(self.lable, text) subscribeNext:^(id  _Nullable x) {
//        NSLog(@"%@",x);
//    }];

    //1.给模型的账号&&密码绑定信号!!
//    RAC(self.loginVM,account) = _accountFiled.rac_textSignal;
//    RAC(self.loginVM,pwd) = _pwdFiled.rac_textSignal;
//    //2.设置按钮
//    RAC(_loginBtn,enabled) = self.loginVM.loginEnableSignal;
//    //3.监听登录按钮的点击
//    [[_loginBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
//        //处理登录事件
//        [self.loginVM.loginCommand execute:@"账号密码"];
//    }];
//
//
    [self RACMulticastConnectionDemo];
}


-(LoginViewModel *)loginVM
{
    //有效避免出错!!
    if (nil == _loginVM) {
        _loginVM = [[LoginViewModel alloc]init];
        
    }
    return _loginVM;
}

#pragma  mark- RACReplaySubject
-(void)RACReplaySubjectDemo{
    //1.创建信号
    RACReplaySubject * subject = [RACReplaySubject subject];
    
    //3.发送信号
    [subject sendNext:@1];
    
    //2.订阅信号
    [subject subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
}
#pragma mark-RAC集合类
-(void)RACSequence
{
    // RACSequence:用于代替NSArray,NSDictionary,可以使用快速的遍历最常见的应用场景:字典转模型!!
    //元祖
    RACTuple * tuple = [RACTuple tupleWithObjectsFromArray:@[@"aaa",@"bbb",@123]];
    NSString * str = tuple[0];
    NSLog(@"%@",str);
//    //包装元祖
//    RACTuple * tuple = RACTuplePack(@1,@2);
//
//    NSLog(@"%@",tuple[0]);
//
//    //解包!!
// RACTupleUnpack(...)
    
    //数组
    NSArray * arr = @[@"abc",@"bbb",@123];
    [arr.rac_sequence.signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    //字典
     NSDictionary * dict = @{@"name":@"hank",@"age":@"18"};
    //字典转集合
    [dict.rac_sequence.signal subscribeNext:^(RACTuple* x) {
        //        NSString * key = x[0];
        //        NSString * value = x[1];
        //        NSLog(@"%@%@",key,value);
        //RACTupleUnpack:用来解析元祖
        //宏里面的参数,传需要解析出来的变量名称
        // = 右边,放需要解析的元祖
        RACTupleUnpack(NSString * key,NSString * value) = x;
        NSLog(@"%@ : %@",key,value);
    }];
    //会将一个集合中的所有元素都映射成一个新的对象!
    NSArray * arrD = [[dict.rac_sequence map:^id _Nullable(NSDictionary * value) {
        //返回模型!!
        return  nil;
    }] array];
    NSLog(@"%@",arrD);
}

    
#pragma mark-RACSubject运用
-(void)timeDemo{
    //RAC tiemr 让你上瘾!!
    [[RACSignal interval:1.0 onScheduler:[RACScheduler scheduler]] subscribeNext:^(NSDate * _Nullable x) {
        NSLog(@"%@",[NSThread currentThread]);
    }];
    
//    //改变按钮状态
//    self.reSendBtn.enabled = NO;
//    //设置倒计时
//    self.time = 10;
//    //每一秒进来
//    self.signal = [RACSignal interval:1.0 onScheduler:[RACScheduler mainThreadScheduler]];
//
//    self.disposable = [self.signal subscribeNext:^(NSDate * _Nullable x) {
//        NSLog(@"%@",self);
//        //时间先减少!
//        _time--;
//        //设置文字
//        NSString * btnText = _time > 0 ? [NSString stringWithFormat:@"请等待%d秒",_time]
//        : @"重新发送";
//        [self.reSendBtn setTitle:btnText forState:_time > 0?(UIControlStateDisabled):(UIControlStateNormal)];
//        //设置按钮
//        if(_time > 0){
//            _reSendBtn.enabled = NO;
//        }else{
//            _reSendBtn.enabled = YES;
//            //取消订阅!!
//            [_disposable dispose];
//        }
//    }];
    
}




-(void)delegateDemo{
    [self.zzView.btnClickSingnal subscribeNext:^(id x) {
        NSLog(@"接受到了数据:%@",x);
    }];
}

-(void)kvo
{
    //1
    [self.zzView rac_observeKeyPath:@"fame" options:NSKeyValueObservingOptionNew observer:self block:^(id value, NSDictionary *change, BOOL causedByDealloc, BOOL affectedOnlyLastComponent) {
        
    }];
    //2
    [[self.zzView rac_valuesForKeyPath:@"frame" observer:self]subscribeNext:^(id  _Nullable x) {
        
    }];
}
-(void)addNotification{
    [[[NSNotificationCenter defaultCenter]rac_addObserverForName:UIKeyboardDidHideNotification object:nil]subscribeNext:^(NSNotification * _Nullable x) {
        
    }];
}
-(void)action{
    [[_btn rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        
    }];
}

#pragma mark- RACSubject
-(void)subjectDemo{
    //1.创建信号,创建信号，创建一个数组,和回收处理
    RACSubject * subject = [RACSubject subject];
    //2.订阅信号,创建一个订阅者，把block放入o对象里面，把订阅者放到第一步创建的数组里面
    //不同的信号订阅的方式不一样!!(因为类型不一样,所以调用的方法不一样)
    //RACSubject处理订阅:拿到之前的_subscribers保存订阅者
    [subject subscribeNext:^(id x) {
        NSLog(@"接受到了数据:%@",x);
    }];
    //3.发送数据
    //遍历出所有的订阅者,调用nextBlock
    [subject sendNext:@"发送数据"];
}


#pragma mark-RACDisposable
-(void)disposableDemo{
    RACSignal * signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
     [subscriber sendNext:@"嘿嘿"];//1
        _subscriber = subscriber;
        return [RACDisposable disposableWithBlock:^{
            //只要信号取消订阅就会来这里
            NSLog(@"清空资源!!");//4
        }];
    }];
    RACDisposable * disposable =  [signal subscribeNext:^(id x) {
        //x:信号发送的内容!!
      NSLog(@"%@",x);//2
        
    }];
    //默认一个信号发送数据完毕就会主动取消订阅,只要订阅者在,就不会自动取消订阅
    //手动取消订阅
    [disposable dispose];//3
}

#pragma mark-RACSignal
-(void)signalDemo
{
    // RACSignal: 信号类,当我们有数据产生,创建一个信号!
    /**1.创建信号(冷信号!)
     didSubscribe调用:只要一个信号被订阅就会调用!!,利用subscriber发送数据!!
     */
    RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        //3.发送数据subscriber它来发送
        [subscriber sendNext:@"subscriber"];
        return nil;
    }];
    /**
     2.订阅信号(热信号!!),nextBlock调用:只要订阅者发送数据就会调用!用于处理数据,展示UI界面!
     */
    [signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"2%@",x);
    }];
}

#pragma mark-rac_lift
-(void)rac_liftDemo{
    //请求1
    RACSignal * signal1 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        //发送请求
        NSLog(@"请求网络数据 1");
        //发送数据
        [subscriber sendNext:@"数据1 来了"];
        
        return nil;
    }];
    
    //请求2
    RACSignal * signal2 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        //发送请求
        NSLog(@"请求网络数据 2");
        //发送数据
        [subscriber sendNext:@"数据2 来了"];
        
        return nil;
    }];
    
    
    
    //数组:存放信号
    //当数组中的所有洗好都发送了数据,才会执行Selector
    //方法的参数:必须和数组的信号一一对应!!
    //方法的参数:就是每一个信号发送的数据!!
    [self rac_liftSelector:@selector(updateUIWithOneData:TwoData:) withSignalsFromArray:@[signal1,signal2]];
    
    
}

- (void)updateUIWithOneData:(id )oneData TwoData:(id )twoData {
    NSLog(@"%@",[NSThread currentThread]);
    //拿到数据更新UI
    NSLog(@"UI!!%@   %@",oneData,twoData);
    
}


#pragma mark-RACMulticastConnection
-(void)RACMulticastConnectionDemo{
    
    //不管订阅多少次信号,就只会请求一次数据
    //RACMulticastConnection:必须要有信号
    //1.创建信号
    RACSignal * signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        
        //发送网络请求
        NSLog(@"发送请求");
        //发送数据
        [subscriber sendNext:@"请求到的数据"];
        
        return nil;
    }];
    
    //2.将信号转成连接类!!
    RACMulticastConnection *connection = [signal publish];
    
    //3.订阅连接类的信号
    [connection.signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"A处在处理数据%@",x);
    }];
    [connection.signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"B处在处理数据%@",x);
    }];
    
    //4.连接
    [connection connect];
    
    
}

#pragma mark-RACCommand

-(void)RACCommand{
    
//    //1.创建命令
//    RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
//        NSLog(@"%@",input);
//        //input:指令
//        //
//        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
//            //发送数据
//            [subscriber sendNext:@"执行完命令之后产生的数据"];
//            return nil;
//        }];
//    }];
//    //2.执行命令
//    RACSignal * signal = [command execute:@"输入的指令!!"];
//    //3.订阅信号!
//    [signal subscribeNext:^(id  _Nullable x) {
//        NSLog(@"%@",x);
//    }];
    
    
    //RACCommand 命令
    //1.创建命令
    RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        NSLog(@"%@",input);
        //input:指令
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            
            //发送数据
            [subscriber sendNext:@"执行完命令之后产生的数据"];
            
            //发送完成
            [subscriber sendCompleted];
            
            return nil;
        }];
    }];
    //监听事件有没有执行完毕
    [command.executing subscribeNext:^(NSNumber * _Nullable x) {
        if([x boolValue]){ //正在执行!!
            NSLog(@"正在执行!!");
        }else{
            NSLog(@"已经结束咯&&还没开始做!");
        }
    }];
    
    
    RACSignal * signal =  [command execute:@"执行!!"];
    [signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"接受到数据了!!%@",x);
    }];
    
    
}
-(void)switchToLatestDemo{
    
    
    
    //创建多个信号
    RACSubject * signalOfSignal = [RACSubject subject];
    RACSubject * signal1 = [RACSubject subject];
    RACSubject * signal2 = [RACSubject subject];
    RACSubject * signal3 = [RACSubject subject];
    
    //订阅信号
    //    [signalOfSignal subscribeNext:^(id  _Nullable x) {
    //       [x subscribeNext:^(id  _Nullable x) {
    //           NSLog(@"%@",x);
    //       }];
    //    }];
    
    //switchToLatest :最新的信号!!
    [signalOfSignal.switchToLatest subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
    //发送信号
    [signalOfSignal sendNext:signal1];
    [signalOfSignal sendNext:signal2];
    [signalOfSignal sendNext:signal3];
    //发送数据
    [signal3 sendNext:@"3"];
    [signal2 sendNext:@"2"];
    [signal1 sendNext:@"1"];
    
    
    
}

-(void)commandDemo{
    //RACCommand 命令
    //1.创建命令
    RACCommand * command = [[RACCommand alloc]initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        NSLog(@"----%@",input);
        //input:指令
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            
            //发送数据
            [subscriber sendNext:@"执行完命令之后产生的数据"];
            
            return nil;
        }];
    }];
    
    //订阅信号
    //executionSignals:信号源!!,发送信号的信号!
    //    [command.executionSignals subscribeNext:^(RACSignal * x) {
    //        [x subscribeNext:^(id  _Nullable x) {
    //            NSLog(@"%@",x);
    //        }];
    //        NSLog(@"%@",x);
    //    }];
    
    //switchToLatest 获取最新发送的信号.
    [command.executionSignals.switchToLatest subscribeNext:^(id  _Nullable x) {
        NSLog(@"--%@",x);
    }];
    //2.执行命令
    [command execute:@"输入的指令!!"];
    
    
    
}

-(void)bind{
        //1.创建信号
        RACSubject * subject = [RACSubject subject];
        //2.绑定信号
        RACSignal * bindSignal = [subject bind:^RACSignalBindBlock _Nonnull{
            return ^RACSignal * (id value, BOOL *stop){
                //block调用:只要源信号发送数据,就会调用bindBlock
                //block作用:处理原信号内容
                //value:源信号发送的内容
                NSLog(@"%@",value);
                //返回信号,不能传nil , 返回空信号 :[RACSignal empty]
                return [RACReturnSignal return:value];
            };
        }];
    
        //3.订阅信号
        [bindSignal subscribeNext:^(id  _Nullable x) {
            NSLog(@"绑定接收到!! %@",x);
        }];
    
        //4.发送
        [subject sendNext:@"发送原始的数据"];
}

-(void)mapDemo{
    //创建信号
    RACSubject * subject = [RACSubject subject];
    
    //绑定
    [[subject map:^id _Nullable(id  _Nullable value) {
        //返回的数据就是需要处理的数据
        return [NSString stringWithFormat:@"处理数据%@",value];
    }] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
    //发送数据
    [subject sendNext:@"123"];
    [subject sendNext:@"321"];
    
}


-(void)flattenMapDemo{
    //创建信号
    RACSubject * subject = [RACSubject subject];
    
    //绑定信号
    RACSignal * bindSignal = [subject flattenMap:^__kindof RACSignal * _Nullable(id  _Nullable value) {
        //block:只要源信号发送内容就会调用
        //value:就是源信号发送的内容
        value = [NSString stringWithFormat:@"处理数据:%@",value];
        
        //返回信号用来包装修改过的内容
        return [RACReturnSignal return:value];
    }];
    
    //订阅绑定信号
    [bindSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    //发送数据
    [subject sendNext:@"123"];
    
}

-(void)zipDemo{
    //zipWith:两个信号压缩!只有当两个信号同时发出信号内容,并且将内容合并成为一个元祖给你
    
    //创建信号
    RACSubject * signalA = [RACSubject subject];
    RACSubject * signalB = [RACSubject subject];
    
    //压缩
    RACSignal * zipSignal =  [signalA zipWith:signalB];
    
    //接受数据  和发送顺序无关!!
    [zipSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    //发送数据
    [signalB sendNext:@"B"];
    [signalA sendNext:@"A"];
    [signalB sendNext:@"B1"];
    [signalA sendNext:@"A1"];
    [signalB sendNext:@"B2"];
    [signalA sendNext:@"A2"];
    
}

-(void)mergeDemo{
    
    //创建信号
    RACSubject * signalA = [RACSubject subject];
    RACSubject * signalB = [RACSubject subject];
    RACSubject * signalC = [RACSubject subject];
    
    
    //组合信号
    //    RACSignal * mergeSignal = [signalA merge:signalB];
    RACSignal * mergeSignal = [RACSignal merge:@[signalA,signalB,signalC]];
    
    //订阅 -- 根据发送的情况接受数据!!
    [mergeSignal subscribeNext:^(id  _Nullable x) {
        //任意一二信号发送内容就会来这个Block
        NSLog(@"%@",x);
    }];
    
    
    
    
    //发送数据
    [signalC sendNext:@"数据C"];
    [signalA sendNext:@"数据A"];
    [signalB sendNext:@"数据B"];
    
    
    
}

-(void)thenDemo{
    //创建信号!!
    RACSignal * signalA = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        NSLog(@"发送请求A");
        //发送数据
        [subscriber sendNext:@"数据A"];
        [subscriber sendCompleted];
        
        return nil;
    }];
    
    RACSignal * signalB = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        NSLog(@"发送请求B");
        //发送数据
        [subscriber sendNext:@"数据B"];
        [subscriber sendCompleted];
        return nil;
    }];
    
    //then:忽略掉第一个信号所有的值!!
    RACSignal * thenSignal = [signalA then:^RACSignal * _Nonnull{
        return signalB;
    }];
    
    //订阅信号
    [thenSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
}

-(void)concatDemo{
    //组合!!
    //创建信号!!
    RACSignal * signalA = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        NSLog(@"发送请求A");
        //发送数据
        [subscriber sendNext:@"数据A"];
        //哥么结束了!!
        [subscriber sendCompleted];
        //        [subscriber sendError:nil]; 这哥么不行!
        
        return nil;
    }];
    
    RACSignal * signalB = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        NSLog(@"发送请求B");
        //发送数据
        [subscriber sendNext:@"数据B"];
        [subscriber sendCompleted];
        return nil;
    }];
    
    RACSignal * signalC = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        NSLog(@"发送请求C");
        //发送数据
        [subscriber sendNext:@"数据C"];
        
        return nil;
    }];
    
    //concat:按顺序组合!!
    //创建组合信号!!
    //    RACSignal * concatSignal = [[signalA concat:signalB] concat:signalC];
    
    RACSignal * concatSignal = [RACSignal concat:@[signalA,signalB,signalC]];
    
    //订阅组合信号
    [concatSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
    
}
-(void)reduceDemo
{
    //组合
    //reduceBlock参数:根据组合的信号关联的  必须 一一对应!!
    RACSignal * signal = [RACSignal combineLatest:@[_accountFiled.rac_textSignal,_pwdFiled.rac_textSignal] reduce:^id _Nullable(NSString * account,NSString * pwd){
        
        //两个文本框的text是否有值!!
        return @(account.length && pwd.length);
    }];
    
    //    //订阅组合信号
    //    [signal subscribeNext:^(id  _Nullable x) {
    //        _loginBtn.enabled = [x boolValue];
    //    }];
    
    RAC(_loginBtn,enabled) = signal;
}


#pragma mark-过滤

-(void)skipDemo
{
    RACSubject * subject = [RACSubject subject];
    
    //skip: 跳跃几个值
    [[subject skip:2] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    [subject sendNext:@"1"];
    [subject sendNext:@"2"];
    [subject sendNext:@"3"];
}

-(void)distinDemo{
    //1.创建信号
    RACSubject * subject = [RACSubject subject];
    
    //忽略掉重复数据
    [[subject distinctUntilChanged] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    //请求回来
    [subject sendNext:@"abc haha hehe"];
    [subject sendNext:@"hehe"];
    [subject sendNext:@"1"];[subject sendNext:@"1"];
    [subject sendNext:@"2"];
    [subject sendNext:@"2"];
    
}

-(void)takeDemo{
    RACSubject * subject = [RACSubject subject];
    
    //take:指定拿前面的哪几条数据!!(从前往后)
    //takeLast:指定拿前面的哪几条数据!!(从后往前)注意点:一定要写结束!!
    [[subject takeLast:2] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    [subject sendNext:@"2"];
    [subject sendNext:@"3"];
    [subject sendNext:@"1"];
    [subject sendCompleted];
    
    
    
    //    RACSubject * subject = [RACSubject subject];
    //专门做一个标记信号!!
    RACSubject * signal = [RACSubject subject];
    
    //take:指定拿前面的哪几条数据!!(从前往后)
    //takeLast:指定拿前面的哪几条数据!!(从后往前)注意点:一定要写结束!!
    //takeUntil:直到你的标记信号发送数据的时候结束!!!
    [[subject takeUntil:signal] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    
    [subject sendNext:@"2"];
    
    //[signal sendNext:@".."];
    [signal sendCompleted];//标记信号!!
    
    [subject sendNext:@"3"];
    [subject sendNext:@"1"];
    [subject sendCompleted];
    
    
    
}

-(void)ignoreDemo{
    
    //ignore:忽略
    RACSubject * subject = [RACSubject subject];
    
    //忽略一些值!!
    RACSignal * ignoreSignal = [[[subject ignore:@"1"] ignore:@"2"] ignore:@"3"];
    
    //订阅
    [ignoreSignal subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    
    //发送数据
    [subject sendNext:@"1"];
    [subject sendNext:@"2"];
    [subject sendNext:@"13"];
    [subject sendNext:@"3"];
}

-(void)filterDemo{
    
    [[_tf.rac_textSignal filter:^BOOL(NSString * _Nullable value) {
        //value:源信号的内容
        return [value length] > 5;
        //返回值:就是过滤条件,只有满足这个条件,才能获取到内容
    }] subscribeNext:^(NSString * _Nullable x) {
        NSLog(@"%@",x);
    }];
    
}



@end
